

#include "PostprocessorNormalVelocityBC.h"
#include "Assembly.h"
#include "MooseVariableFE.h"
#include "SystemBase.h"

#include "libmesh/quadrature.h"
registerMooseObject("TrilobitaApp", PostprocessorNormalVelocityBC);

// Used by MOOSEDocs: syntax/Postprocessors/index.md
defineLegacyParams(PostprocessorNormalVelocityBC);

InputParameters
PostprocessorNormalVelocityBC::validParams()
{
    InputParameters params = NodalBC::validParams();
    params.addCoupledVar("nx","x-component of the normal");
    params.addCoupledVar("ny","y-component of the normal");
    params.addCoupledVar("nz","z-component of the normal");
    params.addRequiredParam<PostprocessorName>(
        "postprocessor", "The postprocessor to set the time derivative value to on the boundary.");
    MooseEnum component("x y z");
    params.addRequiredParam<MooseEnum>("component", component, "The desired component of velocity.");
    params.set<std::vector<VariableName> >("nx") = std::vector<VariableName>(1, "nodal_normal_x");
    params.set<std::vector<VariableName> >("ny") = std::vector<VariableName>(1, "nodal_normal_y");
    params.set<std::vector<VariableName> >("nz") = std::vector<VariableName>(1, "nodal_normal_z");
    params.addCoupledVar("variableold", "variable");
    return params;
}

PostprocessorNormalVelocityBC::PostprocessorNormalVelocityBC(const InputParameters& parameters)
    : NodalBC(parameters), 
    _component(getParam<MooseEnum>("component")),
    _nx(coupledValueOld("nx")),
    _ny(coupledValueOld("ny")),
    _nz(coupledValueOld("nz")),
    _oldu(coupledValueOld("variableold")),
    _postprocessor_value(getPostprocessorValue("postprocessor"))
{
}

Real
PostprocessorNormalVelocityBC::computeQpResidual()
{
    if (_component == 0)
    {
        return _u[_qp] - _oldu[_qp] + _postprocessor_value * _nx[_qp] * _dt;
    }
    else
    {
        if (_component == 1)
        {
            return _u[_qp] - _oldu[_qp] + _postprocessor_value * _ny[_qp] * _dt;
        }
        else
        {
            return _u[_qp] - _oldu[_qp] + _postprocessor_value * _nz[_qp] * _dt;
        }
    }
}
